/**
 * @author 徐楠
 * @date 2022/5/15 8:59
 * @version 1.0
 */

package com.xunan.likou;

public class JudgmentSubsequence {
    public static void main(String[] args) {
        String s = "abc";
        //String s = "axc";
        String t = "ahbgdc";
        //String s = "aaaaaa";
        //String t = "bbaaaa";
        boolean subsequence = isSubsequence(s, t);
        System.out.println(subsequence);
    }

    public static boolean isSubsequence(String s, String t) {
        if (s.isEmpty()) {
            return true;
        }
        if (t.isEmpty()) {
            return false;
        }
        char[] tChars = t.toCharArray();
        char[] sChars = s.toCharArray();
        int sLength = sChars.length;
        int tLength = tChars.length;
        System.out.println(sLength);
        System.out.println(tLength);
        int start = 0;
        for (int i = 0; i < sLength; i++) {
            boolean judge = true;
            for (int j = start; j < tLength; j++) {
                start++;
                if (sChars[i] == tChars[j]) {
                    judge = true;
                    break;
                } else {
                    judge = false;
                }
            }

            if (!judge) {
                return false;
            }
            if ((tLength - start) < (sLength - i - 1)){
                return false;
            }
        }

        return true;
    }
}
